package com.github.common.extend.demo.config.json;

import com.fasterxml.jackson.annotation.JacksonAnnotationsInside;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.github.common.extend.demo.config.json.jaskson.filter.ValueFormatSerializer;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import static com.github.common.extend.demo.config.json.jaskson.filter.ValueFormatSerializer.PLACEHOLDER;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;

/**
 * 匹配{@link #pattern()}，则fastjson框架序列化时输出特定值{@link #writeValue()}
 * @author X1993
 * @date 2022/11/16
 * @description
 */
@Target({METHOD, FIELD ,})
@Retention(RetentionPolicy.RUNTIME)
@JacksonAnnotationsInside
@JsonSerialize(using = ValueFormatSerializer.class)
public @interface ValueFormat {

    /**
     * 匹配规则，正则表达式
     * 空值：默认匹配
     * @return
     */
    String pattern() default "";

    /**
     * 处理后的序列化值写入的属性名
     * 空：默认当前属性
     * @return
     */
    String writeProperty() default "";

    /**
     * 序列化值，占位符使用规则参考{@link java.text.MessageFormat#format(String, Object...)}
     * @return
     */
    String writeValue() default PLACEHOLDER;

}
